﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Xml;
using System.Windows.Forms;

namespace FinancialDB
{
    partial class newColumn_Form : Form
    {
        public newColumn_Form()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            XmlDocument xmldoc = new XmlDocument();
            xmldoc.Load(@"../../Users/userdata.xml");
            if (xmldoc.SelectNodes("/root/homepage/column[@name='" + this.textBox1.Text + "']").Count != 0)
            {
                DialogResult result = MessageBox.Show("该栏目名已存在！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                if (result == DialogResult.OK)
                {
                    this.textBox1.Text = "";
                }
            }
            else
            {
                XmlNode root = xmldoc.SelectSingleNode("/root/homepage");
                XmlElement col = xmldoc.CreateElement("column");
                col.SetAttribute("name", this.textBox1.Text);
                root.AppendChild(col);
                xmldoc.Save(@"../../Users/userdata.xml");

                Form form = Application.OpenForms["addHomepage_Form"];
                TreeView treeview = form.Controls.Find("treeView1", true)[0] as TreeView;
                TreeNode tn = new TreeNode();
                tn.Text = this.textBox1.Text;
                treeview.Nodes[0].Nodes.Add(tn);
                treeview.SelectedNode = tn;
                treeview.ExpandAll();

                this.Close();
            }            
        }
    }
}
